package com.itheima.web;

import com.itheima.pojo.OrderSetting;
import com.itheima.service.OrderSettingService;
import com.itheima.utils.POIUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/ordersetting")
public class OrderSettingController {

    @DubboReference
    private OrderSettingService orderSettingService;

    @PostMapping("/import")
    public void importData(@RequestParam("file") MultipartFile multipartFile) throws IOException {
        List<String[]> list = POIUtils.readExcel(multipartFile.getInputStream(),multipartFile.getOriginalFilename());
        orderSettingService.importData(list);
    }

    @GetMapping("/findByYearMonth/{year}/{month}")
    public Map<String, OrderSetting> findByYearMonth(@PathVariable("year") Integer year,@PathVariable("month") Integer month){
        return orderSettingService.findByYearMonth(year,month);
    }

    @GetMapping("/oneDaySetting/{day}/{num}")
    public boolean oneDaySetting(@PathVariable("day") String day,@PathVariable("num") Integer num){
        return orderSettingService.oneDaySetting(day,num);
    }

}
